package com.fare.taluo.core.domain.crawl.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.dayatang.hibernate.EntityRepositoryHibernate;
import com.fare.taluo.core.domain.crawl.PersistentRecordeEntity;
import com.fare.taluo.core.domain.crawl.PersistentRecordeEntityRepository;

@Repository
public class PersistentRecordeEntityRepositoryImpl extends EntityRepositoryHibernate implements PersistentRecordeEntityRepository{

	@Override
	public List<PersistentRecordeEntity> findAll() {
//		return super.findAll(PersistentRecordeEntity.class);
		
		StringBuffer sbf=new StringBuffer("from PersistentRecordeEntity a where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		
		sbf.append(" order by a.createTime desc");//此排序不可删除，否则直接影响持久化操作
		List<PersistentRecordeEntity> list = new ArrayList<PersistentRecordeEntity>();
		list=this.find(sbf.toString(),params.toArray(),PersistentRecordeEntity.class);
		return list;
		
	}

	@Override
	public List<PersistentRecordeEntity> findByGrabDate(Date grabDate) {
		StringBuffer sbf=new StringBuffer("from PersistentRecordeEntity a where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		if( grabDate !=null ){
			sbf.append(" and a.finishedGrabDate= ?");
			params.add(grabDate);
		}
		sbf.append(" order by a.createTime desc");
		
		List<PersistentRecordeEntity> list = new ArrayList<PersistentRecordeEntity>();
		list=this.find(sbf.toString(),params.toArray(),PersistentRecordeEntity.class);
		return list;
	}

	@Override
	public void updateVO(PersistentRecordeEntity entity) {
		Session session = super.getSession();
		session.merge(entity);
	}
	
	

}
